package org.FaPe3D.engine.elements
{
	import flash.filters.GlowFilter;
	import org.FaPe3D.Adapter;
	import org.FaPe3D.engine.modifiers.*;
	import org.FaPe3D.utils.InitialValues;
	import org.FaPe3D.utils.MouseOverManager;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.*;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.layer.util.ViewportLayerSortMode;
	
	public class FPPlane extends Plane
	{
		private var _width:Number;
		private var _height:Number;
		private var _depth:Number;
		private var _hand;
		private var _bend:FPBend;
		private var _index:int;
		private var _quickB:Object;
		
		public function FPPlane(material:MaterialObject3D=null, width:Number=100, height:Number=100, segmentsW:Number=5, segmentsH:Number=5, initObject:Object=null)
		{
			_width = width;
			_height = height;
			_depth = InitialValues.MinDepth;
			super(material, _width, _height, segmentsW, segmentsH, initObject);
		}
		
		public function get index():int
		{
			return _index;
		}
		
		public function set index(num:int):void
		{
			Adapter.getCurrentAdapter().viewports.getDefaultViewport().containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;
			_index = num;
			Adapter.getCurrentAdapter().viewports.getDefaultViewport().getChildLayer(this, true).layerIndex = _index;
			Adapter.getCurrentAdapter().viewports.getDefaultViewport().getChildLayer(this, true).filters = [new GlowFilter(0x171717, 1, 1, 1, 1, 2)];;
		}
		
		public function get quickBend():Object
		{
			return _quickB;
		}
		
		public function set quickBend(params:Object):void
		{
			_quickB = params;
			_bend = new FPBend(this);
			_bend.quickBend(params.force,params.offset);
		}
		
		public function get useHandCursor():Boolean
		{
			return _hand;
		}
		
		public function set useHandCursor(action:Boolean):void
		{
			_hand = action;
			if(_hand == true)
			{
				this.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,MouseOverManager.rollOver);
				this.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,MouseOverManager.rollOut);
			}
			if(_hand == false)
			{
				if(this.hasEventListener(InteractiveScene3DEvent.OBJECT_OVER))
				{
					this.removeEventListener(InteractiveScene3DEvent.OBJECT_OVER,MouseOverManager.rollOver);
					this.removeEventListener(InteractiveScene3DEvent.OBJECT_OUT,MouseOverManager.rollOut);
				}
			}
		}
		
		public function get width():Number
		{
			return _width;
		}
		
		public function set width(num:Number):void
		{
			this.scaleX = num /_width;
			_width = num;
		}
		
		public function get height():Number
		{
			return _height;
		}
		
		public function set height(num:Number):void
		{
			this.scaleY = num /_height;
			_height = num;
		}
		
		public function get depth():Number
		{
			return _depth;
		}
		
		public function set depth(num:Number):void
		{
			this.scaleZ = num /_depth;
			_depth = num;
		}
		
	}
}